package cn.rongdao.jrkabao.ui.information.adapter.baseadapter;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Wang on 2017/2/17.
 */
    public class BaseViewHolder extends RecyclerView.ViewHolder {
        private SparseArray<View> mViews;////缓存itemView内部的子View
        private View mConvertView;
        public BaseViewHolder(View itemView) {
            super(itemView);
            mConvertView = itemView;
            mViews = new SparseArray<>();
        }
        /**
         * 加载layoutId视图
         */
        protected static BaseViewHolder getViewHolder(ViewGroup parent, int layoutId) {
            View itemView = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
            return new BaseViewHolder(itemView);
        }
        /**
         * 根据ItemView的id获取子视图View
         */
        public View getView(int viewId) {
            View view = mViews.get(viewId);
            if (view == null) {
                view = mConvertView.findViewById(viewId);
                mViews.put(viewId, view);
            }
            return view;
        }
    }
